<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .img{
            width: 40px;
            height: 40px;
        }
        .star-front{
            position: absolute;
            top: 33px;
            white-space: nowrap;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <div id="app">
        <input v-model="a">
        <star :total="5" v-model="a"></star>
    </div>
</body>
<script src="./vue.js"></script>
<script type="text/html" id="star">
    <div class="star-box">
        <div class="star-back">
            <img class="img" src="./2.png" alt="" v-for="n in total" @clack="frontClick(n)">
        </div>
        <div class="star-front" :style="frontStyle">
            <img class="img" src="./1.png" alt="" v-for="n in total" @clack="frontClick(n)">
        </div>
    </div>
</script>
<script>
    Vue.component("star",{
        template:"#star",
        props:{
            total:{
                default:5,
                type:Number,
            },
            value:{
                type:Number
            }
        },
        computed:{
            frontStyle:function(){
                var w = 50*this.value
                return{
                    width:w+'px'
                }
            }
        },
        methods:{
            frontClick:function(n){
                this.$emit("input",n)
            }
        }
    })

    new Vue({
        el:"#app",
        data:{
            a:2
        },
        methods:{
            input:function(e){
                this.value=e
            }
        }
    })
</script>
</html>